<?php
class Login_Data_Forgoten {
	
	private $database;
	private $password;
	private $forgoten;
	
	public function __construct(){
		$this->database = new Core_Driver_MysqlImproved();
		$this->password = new Core_Data_Password();
		$this->forgoten = new Core_Data_Forgot();
	}
	
	public function updatePassword(array $postVars){
		$this->database->connect();
		$email = $postVars['email'];
		$email = $this->database->escape($email);
		$password = $this->password->generatePassword();
		$password = $this->database->escape($password);
		$this->database->prepare(
		"UPDATE users SET users_password = '$password' WHERE users_email = '$email';"
		);
		$this->database->query();
		$this->database->dataOperations();
		$this->forgoten->mailValues($password, $email);
		echo '<meta http-equiv="Refresh" content="0;url='.SERVER_ROOT.'?login&page=login">';
	}
}